home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ov143b.zip / OVATTRIB.C < prev    next >
C/C++ Source or Header  |  1993-01-04  |  7KB  |  227 lines

  1. /*  019  23-May-87  ovattrib.c
  2.  
  3.         Copyright (c) 1987 by Blue Sky Software.  All rights reserved.
  4. */
  5.  
  6. #include "ov.h"
  7. #include "overr.h"
  8. #include "dialog.h"
  9. #include "menu.h"
  10. #include "direct.h"
  11.  
  12. extern MENU top_file_menu[], *top_menu;
  13.  
  14. int attrib_a(), attrib_h(), attrib_r(), attrib_s(), attrib_set(), attrib_quit();
  15.  
  16. MENU top_attrib_menu[] = {
  17.    { "Enter", "Change the attributes as shown", attrib_set, top_file_menu },
  18.    { "Archive", "Toggle the Archive attribute", attrib_a, NULL },
  19.    { "Hidden", "Toggle the Hidden attribute", attrib_h, NULL },
  20.    { "Read/only", "Toggle the Read/Only attribute", attrib_r, NULL },
  21.    { "System", "Toggle the System attribute", attrib_s, NULL },
  22.    { "Quit", "Don't change the current attributes", attrib_quit, top_file_menu },
  23.    { NULL, NULL, NULL, NULL }
  24. };
  25.  
  26. static D_BOX attrib_box = { FIRST_NROW+3, 28, 4, 24, NULL, "Set Attributes" };
  27.  
  28. static char *file_to_set;
  29. static unsigned char box_open;
  30. static unsigned char attrib_to_set;
  31. static char *tagged_name = "TAGGED FILES";
  32.  
  33. extern WINDOW cw;
  34. extern FILE_ENT files[];
  35. extern char *none_tagged;
  36. extern unsigned char attribs[], restricted;
  37.  
  38.  
  39. /******************************************************************************
  40.  **                    A T T R I B _ C U R R E N T                           **
  41.  *****************************************************************************/
  42.  
  43. attrib_current() {     /* set the attributes of the current file */
  44.  
  45.    FILE_ENT *fp = &files[cw.curidx];
  46.  
  47.    /* setup the attribute screen with current file name and current file
  48.       attributes */
  49.  
  50.    attrib_setup(fp->name,fp->flags & (RDONLY | HIDDEN | SYSTEM | ARCHIVE));
  51. }
  52.  
  53.  
  54. /******************************************************************************
  55.  **                    A T T R I B _ T A G G E D                             **
  56.  *****************************************************************************/
  57.  
  58. attrib_tagged() {      /* set the attributes of all tagged files */
  59.  
  60.    if (cw.num_tagged == 0)             /* are there any tagged files? */
  61.       show_error(0,NONE_TAGGED,1,none_tagged);
  62.  
  63.    /* setup the attribute screen with tagged file indicator and default
  64.       attributes (none) */
  65.  
  66.    attrib_setup(tagged_name,0);
  67. }
  68.  
  69.  
  70. /******************************************************************************
  71.  **                      A T T R I B _ Q U I T                               **
  72.  *****************************************************************************/
  73.  
  74. attrib_quit() {        /* quit the attribute setup with changing any */
  75.  
  76.    top_menu = top_file_menu;   /* restore file menu as main */
  77.  
  78.    restricted = FALSE;         /* enable all commands */
  79.  
  80.    /* remove the dialog box if attrib_set didn't already */
  81.  
  82.    if (box_open) {
  83.       dbx_close(&attrib_box);
  84.       box_open = FALSE;
  85.    }
  86. }
  87.  
  88.  
  89. /******************************************************************************
  90.  **                    A T T R I B _ S E T U P                               **
  91.  *****************************************************************************/
  92.  
  93. attrib_setup(name,def_attribs) /* setup the attribute modification window */
  94. char *name;
  95. int def_attribs;
  96. {
  97.  
  98.    top_menu = top_attrib_menu; /* setup the attrib menu as the main menu */
  99.  
  100.    restricted = TRUE;          /* disable cursor movement, etc */
  101.  
  102.    setvattrib(DIS_BOX);                /* open dialog box */
  103.    dbx_open(&attrib_box,DBX_SAVE);
  104.    box_open = TRUE;
  105.  
  106.    setvattrib(DIS_HIBOX);              /* display the allowed attrib settings */
  107.    dbx_disp(&attrib_box," R H S A ",1,14);
  108.  
  109.    setvattrib(DIS_BOX);
  110.    dbx_goto(&attrib_box,2,1);          /* display the file name */
  111.    out_str(name,22,' ');
  112.  
  113.    dbx_goto(&attrib_box,2,14);         /* display the initial attributes */
  114.    disp_attrib(def_attribs);
  115.  
  116.    setvattrib(DIS_NORM);
  117.  
  118.    file_to_set = name;                 /* remember the settings */
  119.    attrib_to_set = def_attribs;
  120. }
  121.  
  122.  
  123. /******************************************************************************
  124.  **                      A T T R I B _ S E T                                 **
  125.  *****************************************************************************/
  126.  
  127. attrib_set() {         /* give the current or tagged the selected attributes */
  128.  
  129.    register int i;
  130.    register FILE_ENT *fp;
  131.  
  132.    /* we are actually going to set attributes, remove the dialog box so its
  133.       not in the way */
  134.  
  135.    dbx_close(&attrib_box);
  136.    box_open = FALSE;
  137.  
  138.    if (file_to_set == tagged_name) {           /* set tagged files? */
  139.       for (i = 0, fp = files; i < cw.nfiles && !brkout(); i++, fp++)
  140.          if (fp->flags & TAGGED)
  141.             change_attrib(fp,i);
  142.  
  143.    } else              /* only set current file */
  144.  
  145.       change_attrib(&files[cw.curidx],cw.curidx);
  146.  
  147.    attrib_quit();                      /* use the quit code to exit */
  148. }
  149.  
  150.  
  151. /******************************************************************************
  152.  **                     C H A N G E _ A T T R I B                            **
  153.  *****************************************************************************/
  154.  
  155. static int
  156. change_attrib(fp,idx)          /* change the attributes of a file */
  157. register FILE_ENT *fp;
  158. register int idx;
  159. {
  160.    char *fn;
  161.  
  162.    fn = fname(fp);
  163.    setattrib(fn,attrib_to_set);        /* zap the file attributes */
  164.    free(fn);
  165.  
  166.    /* update the flags in the files[] structure */
  167.  
  168.    fp->flags = (fp->flags & ~(ARCHIVE | RDONLY | HIDDEN | SYSTEM)) | attrib_to_set;
  169.  
  170.    /* update the display if attributes are shown and this file is on screen */
  171.  
  172.    if (cw.info_display && on_screen(idx)) {
  173.       gotorc(idx2sr(idx),idx2sc(idx));
  174.       disp_file(fp,idx == cw.curidx);
  175.    }
  176. }
  177.  
  178.  
  179. /******************************************************************************
  180.  **                           A T T R I B _ x                                **
  181.  *****************************************************************************/
  182.  
  183. static int
  184. attrib_a() {           /* toggle the ARCHIVE attribute */
  185.  
  186.    attrib_toggle(ARCHIVE);
  187. }
  188.  
  189.  
  190. static int
  191. attrib_r() {           /* toggle the READ ONLY attribute */
  192.  
  193.    attrib_toggle(RDONLY);
  194. }
  195.  
  196.  
  197. static int
  198. attrib_h() {           /* toggle the HIDDEN attribute */
  199.  
  200.    attrib_toggle(HIDDEN);
  201. }
  202.  
  203.  
  204. static int
  205. attrib_s() {           /* toggle the SYSTEM attribute */
  206.  
  207.    attrib_toggle(SYSTEM);
  208. }
  209.  
  210.  
  211. /******************************************************************************
  212.  **                      A T T R I B _ T O G G L E                           **
  213.  *****************************************************************************/
  214.  
  215. static int
  216. attrib_toggle(at)      /* toggle the state of the passed attribute */
  217. int at;
  218. {
  219.  
  220.    attrib_to_set ^= at;                /* first toggle the attribute */
  221.  
  222.    dbx_goto(&attrib_box,2,14);         /* then redisplay the current settings */
  223.    setvattrib(DIS_BOX);
  224.    disp_attrib(attrib_to_set);
  225.    setvattrib(DIS_NORM);
  226. }
  227.